#lang scheme

(define (foldr func end lst)
  (if (null? lst)
      end
      (func (car lst) (foldr func end (cdr lst)))))
(foldr + 1 (list 1 2 3 4 5))

;;尾部递归
(define (foldl func accum lst)
  (if (null? lst)
      accum
      (foldl func (func accum (car lst)) (cdr lst))))

(foldl + 1 (list 1 2 3))

(define reduce foldl)                ;reduce函数就是尾部递归
